package org.i0o.webplus.commons.util.populator.converters;

/**
 * @author <a href="mailto:781131@gmail.com">HTF</a>
 * @version 2010-6-1
 */
public final class CharacterConverter extends BaseConverter {

	@Override
	protected Object convertToType(Object value, Class<?> targetType, Object... configs) {
		return new Character(value.toString().charAt(0));
	}

	@Override
	protected Class<?> getDefaultType() {
		return Character.class;
	}

	@Override
	protected String convertToString(Object value) {
		String stringValue = (String) value;
		return stringValue.length() == 0 ? "" : stringValue.substring(0, 1);
	}

}
